package com.lzy.mall.member.service.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.lzy.mall.common.utils.PageParaUtils;
import com.lzy.mall.common.utils.PageUtils;
import com.lzy.mall.member.entity.UmsMemberLevel;
import com.lzy.mall.member.dao.UmsMemberLevelDao;
import com.lzy.mall.member.service.UmsMemberLevelService;
import org.beetl.sql.core.engine.PageQuery;
import org.beetl.sql.core.query.LambdaQuery;
import org.springframework.stereotype.Service;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;


/**
 * 会员等级(UmsMemberLevel)表服务实现类
 *
 * @author lzy
 * @since 2021-08-25 11:38:50
 */
@Service
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class UmsMemberLevelServiceImpl implements UmsMemberLevelService {
    private final UmsMemberLevelDao memberLevelDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        PageQuery pageQuery = PageParaUtils.pagePara(params);
        PageQuery<UmsMemberLevel> page = memberLevelDao.queryPage(pageQuery);
        return new PageUtils(page);
    }

    @Override
    public UmsMemberLevel info(Long id) {
        return memberLevelDao.single(id);
    }

    @Override
    public void update(UmsMemberLevel memberLevel) {
        memberLevelDao.updateTemplateById(memberLevel);
    }

    @Override
    public void save(UmsMemberLevel memberLevel) {
        memberLevelDao.insertTemplate(memberLevel);
    }

    @Override
    public void removeBath(List<Long> levelIds) {
        memberLevelDao.createLambdaQuery()
                .andIn(UmsMemberLevel::getId,levelIds)
                .delete();
    }

    @Override
    public UmsMemberLevel getDefaultInfo() {
        return memberLevelDao.createLambdaQuery()
                .andEq(UmsMemberLevel::getDefaultStatus,1)
                .single();
    }
}
